package com.qf.android.huihui.adapter.shopping;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.qf.android.huihui.R;
import com.qf.android.huihui.bean.ShoppingBean;
import com.qf.android.huihui.common.IClickListern;
import com.qf.android.huihui.utils.snackbar.ScreenUtil;

import java.util.List;

/**
 * Created by 韩爽 on 2017/1/9.
 */

public class ShoppingBottomAdapter extends RecyclerView.Adapter<ShoppingBottomAdapter.MyViewHolder> implements View.OnClickListener{
    private List<ShoppingBean.DataBean.BottomBean> bottom;
    private Context context;
    private IClickListern listern=null;
    public ShoppingBottomAdapter(List<ShoppingBean.DataBean.BottomBean> bottom, Context context) {
        this.bottom = bottom;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.fragment_recyclerview_head_bottom_item,parent,false);
        view.getLayoutParams().width= ScreenUtil.getScreenWidth(context)/3;
        view.setOnClickListener(this);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ShoppingBean.DataBean.BottomBean bean = bottom.get(position);
        holder.textView.setText(bean.getTitle());
        Glide.with(context).load(bean.getImageUrl()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
        holder.itemView.setTag(bean.getUrl());
    }

    @Override
    public int getItemCount() {
        return bottom!=null?bottom.size():0;
    }

    @Override
    public void onClick(View v) {
        if(listern!=null){
            listern.OnItemClick(v,(String)v.getTag());
        }
    }
    public void setMyClickListener(IClickListern listener) {
        this.listern = listener;
    }
    public class MyViewHolder extends RecyclerView.ViewHolder {
          private  TextView  textView;
          private  ImageView imageView;
          public MyViewHolder(View itemView) {
            super(itemView);
            textView= (TextView) itemView.findViewById(R.id.fragment_recyclerview_head_bottom_item_text);
            imageView= (ImageView) itemView.findViewById(R.id.fragment_recyclerview_head_bottom_item_image);
          }
    }
}
